package com.lepu.app.fun.chat.util;

import android.util.Log;

import com.app.application.MyApplication;
import com.app.utils.LoginUtil;
import com.app.utils.Setting;
import com.core.lib.utils.main.LogUtilBase;
import com.lepu.app.fun.chat.core.ChatManager;
import com.lepu.app.usercenter.bean.LoginInfo;

public class AppCommonService {

	private static final String TAG = "AppCommonService";
	private static AppCommonService mInstance = null;
	
	private AppCommonService() {
		
	}

	public static AppCommonService getInstance() {
		if(mInstance == null)
		{
			mInstance = new AppCommonService();
		}
		return mInstance;
	}

	public int getOfflineMsgIQQueryTime() {
		return 5000;
	}

	/**
	 * 登陆 xmpp
	 */
	public void setupChatService() {
		//LoginUtil.getPassword(MyApplication.getInstance())
		if (LoginUtil.checkIsLogin()) {
			LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();
			ChatManager.getInstance().login(Setting.CHAT_SERVICE_HOST,
					Setting.CHAT_SERVICE_PORT, Long.valueOf(loginInfo.UserID),
					loginInfo.LoginToken);
		}
	}

	/**
	 * 退出xmpp
	 */
	public void logoutXGXMPP() {
		Runnable run = new Runnable() {
			@Override
			public void run() {
				try {
					ChatManager.getInstance().logout();
					LogUtilBase.LogD(TAG, "xmpp exit success ");
				} catch (Exception ex) {
					LogUtilBase.LogD(TAG, "xmpp exit fail ");
				}
			}
		};
		new Thread(run).start();
	}
}
